/**
 * 功能描述
 */

define(function(require, exports, module) {
	var Grid = require("grid");
	var instance = {
		initComponent : function(params, widget) {
			var grid = new Grid({
				parentNode : ".J-grid",
				url : "api/cate/mealrecord/queryAll",
        		params :function(){
        			var subnav = widget.get("subnav");
        			var obj={
        					"startDate":subnav.getValue("recordDate").start,
        					"endDate":subnav.getValue("recordDate").end,
        					fetchProperties:"*",
        			}
        			return obj;
        		},
        		model:{
        			columns:[{
        				name:"name",
        				label:"姓名",
        			},{
        				name:"idNumber",
        				label:"身份证号",
        			},{
        				name:"sex",
        				label:"性别",
        				format:function(value,row){
        					row.totalMoney = parseFloat(row.totalMoney).toFixed(2)
        					if(value=="Male"){
        						return "男";
        					}else if(value=="FeMale"){
        						return "女";
        					}else{
        						return "";
        					}
        				}
        			},{
        				name:"totalMoney",
        				label:"消费金额(元)",
        				 format: "detail",
        	             formatparams: {
        	            	 key: "detail",
                     		 handler: function(index,data,rowEle){
                     			// console.log(data);
                     			var subnav = widget.get("subnav");
                	        	var recordDate = subnav.getValue("recordDate");
                     			 widget.hide([".J-grid"]).show([".J-detailgrid"]);
                    			 widget.get("subnav").show(["return"]).hide(["recordDate"]);
                     			 widget.get("detailgrid").refresh({
                     				pkConsumerAccount:data.pkConsumerAccount,
                        	        "startDate":recordDate.start,
                        	        "endDate":recordDate.end,
                        	         fetchProperties:"*,dishes.*"
                     			 },function(data2){
                     				var j = 0;
                     				for(var i in data2){
                     					j+=(data2[i].money == null ? 0 : Number(data2[i].money));
                     				}
                     				var k = parseFloat(j).toFixed(2);
                     				widget.get("detailgrid").setTitle(data.name+" 共消费" + k + "元");
                     			 });
                     		}
        	             }
        			}]
        		}
			});
			widget.set("grid",grid);
		}
	};
	module.exports = instance;
});
